var currentUserId = "";
var currentUserName = "";
var currentCourseId = "";
var currentCourseName = "";
var currentAssignmentId = "";
var currentAssignmentName = "";
var currentActivityId = "";
var currentActivityName = "";
var assignmentPadId="";
var asName="";
var asRftIds="";
$(function(){
	$.ajax({
		url:'/pad/getSessionUser',
		success:function(user){
			currentUserId = user.id;
			currentUserName = user.realname;
			$("#user").html(user.realname+' <span class="caret"></span>');
		}
	});
	
	$.ajax({
		url:'/pad/reflection/getRftFbTemplates',
		success:function(data){
		
		    for(var i=0;i<data.length;i++){//早上来了 html里修改作业中 加反馈模板 select。直接在下面赋值
		    	$("#modifyRftFbTptIdSelect").append('<option value="'+data[i].id+'">'+data[i].templateName+'</option>')
		    	$("#rftFbTptIdSelect").append('<option value="'+data[i].id+'">'+data[i].templateName+'</option>')
		    }
		}
	});
	
	$.ajax({
		url:'/pad/reflection/getRftDimTipTemplates',
		success:function(data){
		
		    for(var i=0;i<data.length;i++){//早上来了 html里修改作业中 加反馈模板 select。直接在下面赋值
		    	$("#rftDimTipTptIdSelect").append('<option value="'+data[i].id+'">'+data[i].templateName+'</option>')
		    	$("#modifyRftDimTipTptIdSelect").append('<option value="'+data[i].id+'">'+data[i].templateName+'</option>')
		    }
		}
	});
	
	$.ajax({
		url:'/pad/assignment/getAsmtDocumentTpts',
		success:function(data){
		    for(var i=0;i<data.length;i++){//早上来了 html里修改作业中 加反馈模板 select。直接在下面赋值
		    	$("#asmtDocumentTptIdSelect").append('<option value="'+data[i].id+'">'+data[i].templateName+'</option>')
		    	$("#modifyAsmtDocumentTptIdSelect").append('<option value="'+data[i].id+'">'+data[i].templateName+'</option>')
		    }
		}
	});
	
	
	$.ajax({
		url:'/pad/comment/getTemplates',
		async: false,// 将异步 请求 设置为false  可以解决  创建/修改作业 选择模板时  出现undefined 的问题 
		success:function(templateList){
			//var htmlStr = '<select name="commentTemplateId" class="commentTemplateSelect form-control selectpicker" placeholder="评论模板"><option value="">--选择评论模板--</option>';
			
			var htmlStrMutual;
			var htmlStr;
			//alert(1)
			//console.log(templateList)
			for(var i in templateList){
				if(templateList[i].templateType=="反馈评论模板"){
					htmlStr +='<option value="'+templateList[i].id+'">'+templateList[i].templateName+'</option>';
				}
				else if(templateList[i].templateType=="互评评论模板"){
					htmlStrMutual +='<option value="'+templateList[i].id+'">'+templateList[i].templateName+'</option>';
				}
			}
			//htmlStr += '</select>';
			$('.reply').each(function(){
				$(this).append(htmlStr);  // 因为是 .reply 所以 它把修改作业时的 评论或者反馈模板也 设置了，所以updateAssignment 里没有设置这一列
			});
			$('.mutual').each(function(){
				$(this).append(htmlStrMutual);
			});
		}
	});
	courseListView();
});



/**
 * 提交表单
 */
function submitForm(formSelecter,modalSelecter){
	
	// 异步提交表单
    $(formSelecter).ajaxSubmit({  
        type:'post',
        resetForm: true,
        success:function(data){ 
        		$('#data-table').bootstrapTable('refresh');
        		$(modalSelecter).modal('hide');
        },
        error:function(msg){
        	alert(msg.statusText);
        }
    });  
}
/**
 * 发送get请求（用来删除记录后更新）
 */
function ajaxGet(url){
    $.ajax({
    	url:url,
    	success:function(data){ 
        	if(data=='success'){
        		$('#data-table').bootstrapTable('refresh');
        	}else{
        		alert(data);
        	}
        },
        error:function(msg){
        	alert(msg.statusText);
        }
    });
}
/*
 * jiaozy
 * 查询该组的行为图
 */
function bubbleReenderer(dom){
	//小组名
	var url=dom.id;
	var type=1;//个人
    var groupType=url.substring(0,2);
    if(groupType=='小组'){
    	type=2;
    }
	//截取组号
	var number=url.substring(2);
	
	var assID=dom.value;
	
	window.open("./NewFile.html?"+number+"?"+assID+"?"+type); 
	
	
}
function manageConst(courseId,courseName,assignmentId,assignmentName){
	currentCourseId = courseId?courseId:"";
	currentCourseName = courseName?courseName:"";
}
function reflectionListView(){
	$('#breadcrumb').html('<li><a href="/pad">首页</a></li><li class="active">课程列表</li>');
	$('#toolbar').html('<button class="btn btn-info" data-toggle="modal" data-target="#createCourseModal"><span class="glyphicon glyphicon-plus"></span>创建课程</button>');
	$('#data-table').bootstrapTable('destroy');
	$('#data-table').bootstrapTable({
	    url: 'course/getCourses',
	    pagination:true,
	    search:true,
	    undefinedText:'',
	    striped:true,
	    showRefresh:true,
	    toolbar:'#toolbar',
	    idField:'id',
	    columns: [
	    	{field: 'year',title: '年份',width:100}, 
	    	{field: 'courseName',title: '课程名'},
	    	{field: 'op',title: '操作',width:250,formatter:function(value,row,index){
	    		return '<a href="javascript:assignmentListView(\''+row.id+'\',\''+row.courseName+'\');" class="btn btn-info btn-xs">进入</a> '+"<a href='javascript:updateCourse("+JSON.stringify(row)+");' class='btn btn-warning btn-xs'>修改</a>"+' <a href="javascript:ajaxGet(\'/pad/course/deleteCourse?courseId='+row.id+'\');" class="btn btn-danger btn-xs">删除</a> <a href="/pad/student_manage.html?courseId='+row.id+'" class="btn btn-info btn-xs">学生管理</a>';
	    	}}]
	});
}
function courseListView(){
	$('#breadcrumb').html('<li><a href="/pad">首页</a></li><li class="active">课程列表</li>');
	$('#toolbar').html('<button class="btn btn-info" data-toggle="modal" data-target="#createCourseModal"><span class="glyphicon glyphicon-plus"></span>创建课程</button>');
	$('#data-table').bootstrapTable('destroy');
	$('#data-table').bootstrapTable({
	    url: 'course/getCourses',
	    pagination:true,
	    search:true,
	    undefinedText:'',
	    striped:true,
	    showRefresh:true,
	    toolbar:'#toolbar',
	    idField:'id',
	    columns: [
	    	{field: 'year',title: '年份',width:100}, 
	    	{field: 'courseName',title: '课程名'},
	    	{field: 'op',title: '操作',width:250,formatter:function(value,row,index){
	    		return '<a href="javascript:assignmentListView(\''+row.id+'\',\''+row.courseName+'\');" class="btn btn-info btn-xs">进入</a> '+"<a href='javascript:updateCourse("+JSON.stringify(row)+");' class='btn btn-warning btn-xs'>修改</a>"+' <a href="javascript:ajaxGet(\'/pad/course/deleteCourse?courseId='+row.id+'\');" class="btn btn-danger btn-xs">删除</a> <a href="/pad/student_manage.html?courseId='+row.id+'" class="btn btn-info btn-xs">学生管理</a>';
	    	}}]
	});
}
function updateCourse(row){
	$('#updateCourse input[name="id"]').val(row.id);
	$('#updateCourse input[name="year"]').val(row.year);
	$('#updateCourse input[name="courseName"]').val(row.courseName);
	$('#updateCourseModal').modal('show');
}
function assignmentListView(courseId,courseName){
	manageConst(courseId,courseName);
	$('input[name="courseId"]').val(courseId);
	$('#breadcrumb').html('<li><a href="/pad">首页</a></li><li><a href="javascript:courseListView();">课程列表</a></li><li class="active">'+courseName+'</li>');
	$('#toolbar').html('<button class="btn btn-info" data-toggle="modal" data-target="#createAssignmentModal"><span class="glyphicon glyphicon-plus"></span>创建作业</button>');
	$('#data-table').bootstrapTable('destroy');
	$('#data-table').bootstrapTable({
	    url: 'assignment/getAssignments?courseId='+courseId,
	    pagination:true,
	    search:true,
	    undefinedText:'',
	    striped:true,
	    showRefresh:true,
	    detailView:true,
	    detailFormatter:function(index,row){
	    	var html = '';
	    	$.ajax({
	    		async: false,
	    		url:'/pad/assignment/getAssignmentGroup?assignmentId='+row.id,
	    		success:function(groupLisst){
	    			html += '<table class="table">';
	    			html+='<tr><th>小组名称</th><th>操作</th></tr>';
	    			$.each(groupLisst, function(index, group){
    	                html += '<tr>';
    	                if(group.groupType=='1'){
    	                	html += '<td>'+group.groupName+'</td>';
    	                }else{
    	                	html += '<td>'+group.groupName+'</td>';
    	                }
    	                html += '<td><button type="button" class="btn btn-danger btn-xs submitInfo" onclick="replacePad(\''+row.id+'\',\''+group.id+'\',\''+group.groupName+'\');">更换pad</button></td></tr>';
	    			});
	    			html += '</table>';
	    		}
	    	});
	    	return html;
	    },
	    toolbar:'#toolbar',
	    // detailView:true,
	    idField:'id',
	    columns: [
	    	{field: 'assignmentName',title: '作业名称'},
	    	{field: 'description',title: '作业描述'},
	    	{field: 'startDate',title: '开始时间',width:100},
	    	{field: 'endDate',title: '结束时间',width:100},
	    	{field: 'op',title: '操作',width:280,formatter:function(value,row,index){
//	    		return '<a href="javascript:activityListView(\''+row.id+'\',\''+row.assignmentName+'\',\''+row.startDate+'\',\''+row.endDate+'\');" class="btn btn-info btn-xs">进入</a> '+"<a href='javascript:updateAssignment("+JSON.stringify(row)+");' class='btn btn-warning btn-xs'>修改</a>"+' <a href="javascript:ajaxGet(\'/pad/assignment/deleteAssignment?assignmentId='+row.id+'\');" class="btn btn-danger btn-xs">删除</a> '+"<a target='_blank' href='./TotalRadar.html?"+row.id+"' class='btn btn-info btn-xs'>可视化整体行为分析</a>&nbsp<a href='javascript:getRftAsmtReferScore("+JSON.stringify(row)+")' class='btn btn-info btn-xs'>导出反思作业参考分</a>";
	    		//console.log(row)
	    		if(row.assignmentType=="1"){
	    		return '<a href="javascript:activityListView(\''+row.id+'\',\''+row.assignmentName+'\',\''+row.startDate+'\',\''+row.endDate+'\');" class="btn btn-info btn-xs">进入</a> '+"<a href='javascript:updateAssignment("+JSON.stringify(row)+");' class='btn btn-warning btn-xs'>修改</a>"+' <a href="javascript:ajaxGet(\'/pad/assignment/deleteAssignment?assignmentId='+row.id+'\');" class="btn btn-danger btn-xs">删除</a> '+"<a target='_blank' href='./TotalRadar.html?"+row.id+"' class='btn btn-info btn-xs'>可视化整体行为分析</a><a target='_blank' href='./refScoreExport.html?"+escape(JSON.stringify(row))+"' class='btn btn-info btn-xs'>导出反思作业参考分</a><a target='_blank' href='./fbContentExport.html?"+escape(JSON.stringify(row))+"' class='btn btn-info btn-xs'>导出反馈内容</a><a target='_blank' href='./sentenceModifyInfoExport.html?"+escape(JSON.stringify(row))+"' class='btn btn-info btn-xs'>导出句子修改信息</a><a target='_blank' href='./rftItemScoreFig.html?"+escape(JSON.stringify(row))+"' class='btn btn-info btn-xs'>反馈分数图</a>";		
	    		}else{
	    		return '<a href="javascript:activityListView(\''+row.id+'\',\''+row.assignmentName+'\',\''+row.startDate+'\',\''+row.endDate+'\');" class="btn btn-info btn-xs">进入</a> '+"<a href='javascript:updateAssignment("+JSON.stringify(row)+");' class='btn btn-warning btn-xs'>修改</a>"+' <a href="javascript:ajaxGet(\'/pad/assignment/deleteAssignment?assignmentId='+row.id+'\');" class="btn btn-danger btn-xs">删除</a> '+"<a target='_blank' href='./TotalRadar.html?"+row.id+"' class='btn btn-info btn-xs'>可视化整体行为分析</a>";
	    		}
	    		}}]
	});
}
//导出学生反思作业参考分数
function getRftAsmtReferScore(assignment){
	$.ajax({
		   url: "/pad/experiment/getCourseRftAsmtRferScores",
		   type: 'POST',
		   data:assignment,
		   async: false,
		   dataType: "json", //返回数据格式为json
		   success: function(data) {//请求成功完成后要执行的方法
			   //console.log(data)
			   var fileTitle=["学号","姓名","得分","经历","情感","信念","视角","困难","自我批判","学习收获","计划"];
			   var fileForKey=["stuNum","name","score","经历","情感","信念","视角","困难","自我批判","学习收获","计划"];
			   var str = [];
		       str.push(fileTitle.join(",")+"\n");
		       for(var i=0;i<data.length;i++){
		            var temp = [];
		            for(var j=0;j<fileForKey.length;j++){
		                temp.push(data[i][fileForKey[j]]);
		         }
		        str.push(temp.join(",")+"\n");
		     }
		     var uri = 'data:text/csv;charset=utf-8,\uFEFF' + encodeURIComponent(str.join(""));  
		     var downloadLink = document.createElement("a");
		     downloadLink.href = uri;
		     downloadLink.download = "反思写作参考分.csv"; 
		     document.body.appendChild(downloadLink);
		     downloadLink.click();
		     document.body.removeChild(downloadLink); 
		   }
	 });
	
	
	
}


function replacePad(assignmentId,groupId,groupName){
	var mymessage=confirm("确认更换\""+groupName+"\"的pad吗？更换pad会清除pad里的所有数据！");  
    if(mymessage==true){
    	$.ajax({
    		url:'/pad/assignment/replacePad?assignmentId='+assignmentId+'&groupId='+groupId,
    		success:function(data){
    			if(data.code=='0')
    				alert("更换成功");
    			else
    				alert("更换失败");
    		}
    	});
    }
}
function updateAssignment(row){
	
	$('#updateAssignment input[name="id"]').val(row.id);
	$('#updateAssignment input[name="assignmentName"]').val(row.assignmentName);
	$('#updateAssignment select[name="assignmentType"]').selectpicker('val', row.assignmentType);
	$('#updateAssignment textarea[name="description"]').val(row.description);
	$('#updateAssignment textarea[name="assignmentContent"]').val(row.assignmentContent);
	$('#updateAssignment input[name="startDate"]').val(row.startDate);
	$('#updateAssignment input[name="endDate"]').val(row.endDate);
	$('#updateAssignmentModal').modal('show');
}
function activityListView(assignmentId,assignmentName,startDate,endDate){
	manageConst(currentCourseId,currentCourseName,assignmentId,assignmentName);
	$('input[name="assignmentId"]').val(assignmentId);
	console.log(startDate + " " +new Date(startDate).format('yyyy-MM-dd'));
	$('#createActivityModal').find('.date-start').datetimepicker('setStartDate',new Date(startDate).format('yyyy-MM-dd'));
	$('#createActivityModal').find('.date-start').datetimepicker('setEndDate',new Date(endDate).format('yyyy-MM-dd'));
	$('#createActivityModal').find('.date-end').datetimepicker('setEndDate',new Date(endDate).format('yyyy-MM-dd'));
	$('#breadcrumb').html('<li><a href="/pad">首页</a></li><li><a href="javascript:courseListView();">课程列表</a></li><li><a href="javascript:assignmentListView(\''+currentCourseId+'\',\''+currentCourseName+'\');">'+currentCourseName+'</a></li><li class="active">'+assignmentName+'</li>');
	$('#toolbar').html('<button class="btn btn-info" data-toggle="modal" data-target="#createActivityModal"><span class="glyphicon glyphicon-plus"></span>创建活动</button>');
	$('#data-table').bootstrapTable('destroy');
	$('#data-table').bootstrapTable({
	    url: 'activity/getActivities?assignmentId='+assignmentId,
	    pagination:true,
	    search:true,
	    undefinedText:'',
	    striped:true,
	    showRefresh:true,
	    detailFormatter:function(index,row){
	    	var html = '';
	    	$.ajax({
	    		async: false,
	    		url:'/pad/activity/getActivityGroupVisions?activityId='+row.id,
	    		success:function(activityGroupVisionList){
	    			html += '<table class="table">';
	    			html+='<tr><td></td><td><button style="margin-right:10px;" onclick="selectValue(this.value)" value="1" id="selectAll1" class="btn btn-warning btn-xs" >全选折线图</button><button id="selectAll2" onclick="selectValue(this.value)" value="2" style="margin-right:10px;" class="btn btn-warning btn-xs" >全选数字饼图</button><button id="selectAll3" onclick="selectValue(this.value)" value="3" style="margin-right:10px;" class="btn btn-warning btn-xs" >全选版本数柱状图</button><button id="selectAll4" onclick="selectValue(this.value)" value="4" style="margin-right:10px;" class="btn btn-warning btn-xs" >全选组内互评雷达图</button><button id="selectAll5" onclick="selectValue(this.value)" value="5" style="margin-right:10px;" class="btn btn-warning btn-xs" >全选组内互评社会网络图</button><button id="selectAll6" onclick="selectValue(this.value)" value="6" style="margin-right:10px;" class="btn btn-warning btn-xs" >全选组间互评雷达图</button><button id="selectAll7" onclick="selectValue(this.value)" value="7" style="margin-right:10px;" class="btn btn-warning btn-xs" >全选组间互评社会网络图</button><button id="selectAll8" onclick="selectValue(this.value)" value="8" style="margin-right:10px;" class="btn btn-warning btn-xs" >全选组内互评策略建议</button><button id="selectAll9" onclick="selectValue(this.value)" value="9" style="margin-right:10px;" class="btn btn-warning btn-xs" >全选组间互评策略建议</button><button id="selectAlla" onclick="selectValue(this.value)" value="a" style="margin-right:10px;" class="btn btn-warning btn-xs" >全选组间互评次数建议</button><button id="saveAll" style="margin-right:10px;" type="button" onclick="saveAllInfo()" class="btn btn-warning btn-xs" >全部保存</button></td></tr>';
	    			html+='<tr><td></td><td><button style="margin-right:10px;" onclick="unSelectValue(this.value)" value="1" id="selectAll1" class="btn btn-warning btn-xs" >不选折线图</button><button id="selectAll2" onclick="unSelectValue(this.value)" value="2" style="margin-right:10px;" class="btn btn-warning btn-xs" >不选数字饼图</button><button id="selectAll3" onclick="unSelectValue(this.value)" value="3" style="margin-right:10px;" class="btn btn-warning btn-xs" >不选版本数柱状图</button><button id="selectAll4" onclick="unSelectValue(this.value)" value="4" style="margin-right:10px;" class="btn btn-warning btn-xs" >不选组内互评雷达图</button><button id="selectAll5" onclick="unSelectValue(this.value)" value="5" style="margin-right:10px;" class="btn btn-warning btn-xs" >不选组内互评社会网络图</button><button id="selectAll6" onclick="unSelectValue(this.value)" value="6" style="margin-right:10px;" class="btn btn-warning btn-xs" >不选组间互评雷达图</button><button id="selectAll7" onclick="unSelectValue(this.value)" value="7" style="margin-right:10px;" class="btn btn-warning btn-xs" >不选组间互评社会网络图</button><button id="selectAll8" onclick="unSelectValue(this.value)" value="8" style="margin-right:10px;" class="btn btn-warning btn-xs" >不选组内互评策略建议</button><button id="selectAll9" onclick="unSelectValue(this.value)" value="9" style="margin-right:10px;" class="btn btn-warning btn-xs" >不选组间互评策略建议</button><button id="selectAlla" onclick="unSelectValue(this.value)" value="a" style="margin-right:10px;" class="btn btn-warning btn-xs" >不选组间互评次数建议</button></td></tr>';
	    			$.each(activityGroupVisionList, function(index, activityGroupVision){
	    				var version = activityGroupVision.vision||"0";
	    				console.log(activityGroupVision.activityId)
    	                html += '<tr>';
    	                html += '<td>'+activityGroupVision.groupName+'</td>'
    	                html += '<td><form class="rowForm" action="activity/saveActivityGroupVision" method="post"><input type="hidden" name="id" value="'+activityGroupVision.id+'"/><input type="hidden" name="activityId" value="'+activityGroupVision.activityId+'"/><input type="hidden" name="groupId" value="'+activityGroupVision.groupId+'"/><input type="hidden" name="groupName" value="'+activityGroupVision.groupName+'"/><input type="hidden" name="groupType" value="'+activityGroupVision.groupType+'"/>';
    	                /*$.ajax({
    	    	    		async: false,
    	    	    		url:'getDictionary?code=VISION',
    	    	    		success:function(dictionaryList){
    	    	    			$.each(dictionaryList, function(index, dictionary){
    	    	    				var vision_n = activityGroupVision.vision==null?"":activityGroupVision.vision;
    	    	    				if(vision_n.indexOf(dictionary.dictTitle)>-1)
    	    	    					html += ' <input name="vision" checked type="checkbox" value="'+dictionary.dictTitle+'" />'+dictionary.dictText;
    	    	    				else
    	    	    					html += ' <input name="vision" type="checkbox" value="'+dictionary.dictTitle+'" />'+dictionary.dictText;
    	    	    			});
    	    	    		}
    	                });*/
    	                version.indexOf("1")>="0"?html+='<input name="vision" checked type="checkbox" value="1" />&nbsp专注度折线图 &nbsp':html+='<input name="vision" type="checkbox" value="1" />&nbsp专注度折线图 &nbsp';
    	                
    	                version.indexOf("2")>="0"?html+='<input name="vision" checked type="checkbox" value="2" />&nbsp字数饼图 &nbsp':html+='<input name="vision" type="checkbox" value="2" />&nbsp字数饼图 &nbsp';

    	                version.indexOf("3")>="0"?html+='<input name="vision" checked type="checkbox" value="3" />&nbsp版本数柱状图 &nbsp':html+='<input name="vision" type="checkbox" value="3" />&nbsp版本数柱状图 &nbsp';

    	                version.indexOf("4")>="0"?html+='<input name="vision" checked type="checkbox" value="4" />&nbsp组内互评雷达图 &nbsp':html+='<input name="vision" type="checkbox" value="4" />&nbsp组内互评雷达图 &nbsp';

    	                version.indexOf("5")>="0"?html+='<input name="vision" checked type="checkbox" value="5" />&nbsp组内互评社会网络图 &nbsp':html+='<input name="vision" type="checkbox" value="5" />&nbsp组内互评社会网络图 &nbsp';
    	               
    	                version.indexOf("6")>="0"?html+='<input name="vision" checked type="checkbox" value="6" />&nbsp组间互评雷达图 &nbsp':html+='<input name="vision" type="checkbox" value="6" />&nbsp组间互评雷达图 &nbsp';
    	                
    	                version.indexOf("7")>="0"?html+='<input name="vision" checked type="checkbox" value="7" />&nbsp组间互评社会网络图 &nbsp':html+='<input name="vision" type="checkbox" value="7" />&nbsp组间互评社会网络图 &nbsp';

    	                version.indexOf("8")>="0"?html+='<input name="vision" checked type="checkbox" value="8" />&nbsp组内互评策略建议&nbsp':html+='<input name="vision" type="checkbox" value="8" />&nbsp组内互评策略建议 &nbsp';
    	                
    	                version.indexOf("9")>="0"?html+='<input name="vision" checked type="checkbox" value="9" />&nbsp组间互评策略建议&nbsp':html+='<input name="vision" type="checkbox" value="9" />&nbsp组间互评策略建议 &nbsp';
    	                
    	                version.indexOf("a")>="0"?html+='<input name="vision" checked type="checkbox" value="a" />&nbsp组间互评次数建议&nbsp':html+='<input name="vision" type="checkbox" value="a" />&nbsp组间互评次数建议&nbsp';
    	                
    	                html += '</select>';
    	                html += '<button type="button" class="btn btn-warning btn-xs submitInfo" onclick="submitSaveActivityGroupVisionForm(this);">保存</button>  &nbsp';
    	                html += '<button type="button" class="btn btn-warning btn-xs "  value ="'+assignmentId+'" id ="'+activityGroupVision.groupName+'" onclick="bubbleReenderer(this);">'+activityGroupVision.groupName+'行为分析</button> &nbsp';
    	                html += '<a type="button" class="btn btn-warning btn-xs "  target="_blank" href="/pad/feedback.html?assignmentPadId='+activityGroupVision.groupId+'$'+assignmentName+'&activityId='+activityGroupVision.activityId+'">查看</a>';
//    	                assignmentPadId=activityGroupVision.groupId;
//    	                asName=assignmentName;
    	                //getAsT('g.5Y5gmPphpJVSsOyA','测试反思维度'); js传参时字符串前后要加 引号 ，需要用转义字符
    	               // html += '<button type="button" class="btn btn-warning btn-xs "  onclick="getAsT(\''+assignmentPadId+'\',\''+asName+'\');">查看</button> &nbsp';
    	                html += '</form></td></tr>';
	    			});
	    			html += '</table>';
	    		}
	    	});
	    	return html;
	    },
	    toolbar:'#toolbar',
	    detailView:true,
	    idField:'id',
	    sortName:'startDate',
	    rowStyle:function rowStyle(row, index) {
	    	if(new Date(row.startDate)>new Date()){
	    		return {
					css: {"color": "#fff","background-color": "#bcd2d8"}
				};
    		}else if(new Date(row.startDate)<new Date() &&　new Date(row.endDate)>new Date()){
    			return {
					css: {"color": "#fff","background-color": "#6de66b"}
				};
    		}else{
    			return {
					css: {"color": "#fff","background-color": "#bbb"}
				};
    		}
	    	
		},
	    columns: [
	    	{field: 'activityType',title: '活动状态',width:100,formatter:function(value,row,index){
	    		if(new Date(row.startDate)>new Date()){
	    			return '即将开始';
	    		}else if(new Date(row.startDate)<new Date() &&　new Date(row.endDate)>new Date()){
	    			return '正在进行';
	    		}else{
	    			return '已结束';
	    		}
	    	}},
	    	{field: 'activityName',title: '活动名称'},
	    	{field: 'description',title: '活动描述'},
	    	{field: 'startDate',title: '开始时间',width:100},
	    	{field: 'endDate',title: '结束时间',width:100},
	    	{field: 'op',title: '操作',width:220,formatter:function(value,row,index){
	    		if(row.activityType=='FEEDBACK')
	    		return "<a href='javascript:updateActivity("+JSON.stringify(row)+");' class='btn btn-warning btn-xs'>修改</a> <a href='javascript:ajaxGet(\"/pad/activity/deleteActivity?activityId="+row.id+"\");' class='btn btn-danger btn-xs'>删除</a> <a target='_blank' href='./radar.html?"+row.id+"?"+currentCourseId+"' class='btn btn-info btn-xs'>查看反馈图</a>";
	    		else  if (row.activityType=='COMMENT')
	    			return "<a href='javascript:updateActivity("+JSON.stringify(row)+");' class='btn btn-warning btn-xs'>修改</a> <a href='javascript:ajaxGet(\"/pad/activity/deleteActivity?activityId="+row.id+"\");' class='btn btn-danger btn-xs'>删除</a> <a href='javascript:exportGroupCommentData("+JSON.stringify(row.id)+','+JSON.stringify(currentCourseId)+");' class='btn btn-info btn-xs'>导出组内互评数据</a>";
	    		else
	    			return "<a href='javascript:updateActivity("+JSON.stringify(row)+");' class='btn btn-warning btn-xs'>修改</a> <a href='javascript:ajaxGet(\"/pad/activity/deleteActivity?activityId="+row.id+"\");' class='btn btn-danger btn-xs'>删除</a> ";
	    	}}]
	});	
}



/*
 * 导出 组内互评数据 一个班级的 	  导出csv
 */
function exportGroupCommentData(aId,cId){
	var activityId =aId;
	var courseId=cId;//课程活动id
	var data=[];
	var _youhao=[];
	var _xinren=[];
	var _user=[];
	var _shuliang=[];
	var _zhiliang=[];
	var _tuandui=[];
	var _yingxiang=[];
	var _xuehao=[];
	var _xiaozuhao=[];
//{信任感=3.75, 友好度=3.75, 工作数量=3.5, 工作质量=3.75, groupNum=6, userName=彭琰, 团队合作能力=3.75, studentNum=222016321081017, 影响力=3.5}
//groupNum:"7" shuliang:0 studentNum:"222014321062064" tuandui:0 userName:"党雪婷" xinren:0 yingxiang:0 youhao:0 zhiliang:0
	var _title=["学号","姓名","小组作业组号","影响力","友好度","团队合作能力","信任感","工作数量","工作质量","影响力"];
	var _titleForKey=["studentNum","userName","groupNum","yingxiang","youhao","tuandui","xinren","shuliang","zhiliang","yingxiang"];
	async: false,
	$.ajax({
		url:'/pad/experiment/getCourseGroupCommentInfo?activityId='+activityId+'&courseId='+courseId,
		method:'GET',
		success:function(data){
			
//			 for(var i=0;i<data.length;i++) {
//		    _youhao.push(data[i].youhao);
//        	__xinren.push(data[i].xinren);
//        	_user.push(data[i].userName);
//        	_shuliang.push(data[i].shuliang);
//        	_zhiliang.push(data[i].zhiliang);
//        	_tuandui.push(data[i].tuandui);
//        	_yingxiang.push(data[i].yingxiang);
//        	__xuehao.push(data[i].studentNum);
//        	_xiaozuhao.push(data[i].groupNum);
//     } 
		
	        var str = [];
	        str.push(_title.join(",")+"\n");
	        for(var i=0;i<data.length;i++){
	            var temp = [];
	            for(var j=0;j<_titleForKey.length;j++){
	                temp.push(data[i][_titleForKey[j]]);
	         }
	        str.push(temp.join(",")+"\n");
	     }
	     var uri = 'data:text/csv;charset=utf-8,' + encodeURIComponent(str.join(""));  
	     var downloadLink = document.createElement("a");
	     downloadLink.href = uri;
	     downloadLink.download = "courseGroupCommentData.csv"; 
	     document.body.appendChild(downloadLink);
	     downloadLink.click();
	     document.body.removeChild(downloadLink); 
			

	}
	}); 
}


function submitSaveActivityGroupVisionForm(dom){
	
	// 异步提交表单
    $(dom).parent('form').ajaxSubmit({  
        type:'post',
        success:function(data){
        	if(data=='success'){
        		console.log(data);
        	}else{
        		alert(data);
        		$('#data-table').bootstrapTable('refresh');
        	}
        },
        error:function(msg){
        	alert(msg.statusText);
        }
    });  
}
function updateActivity(row){
	$('#updateActivity input[name="id"]').val(row.id);
	$('#updateActivity input[name="activityName"]').val(row.activityName);
	$('#updateActivity input[name="description"]').val(row.description);
	$('#updateActivity select[name="activityType"]').selectpicker('val', row.activityType);
	$('#updateActivity input[name="startDate"]').val(row.startDate);
	$('#updateActivity input[name="endDate"]').val(row.endDate);
	$('#updateActivity select[name="commentTemplateId"]').selectpicker('val', row.commentTemplateId);
	$('#updateActivityModal').modal('show');
}

$(function(){
    /**
	 * 时间对象的格式化;
	 */  
    Date.prototype.format = function(format) {  
        /*
		 * eg:format="yyyy-MM-dd hh:mm:ss";
		 */  
        var o = {  
            "M+" : this.getMonth() + 1, // month
            "d+" : this.getDate(), // day
            "h+" : this.getHours(), // hour
            "m+" : this.getMinutes(), // minute
            "s+" : this.getSeconds(), // second
            "q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
            "S" : this.getMilliseconds()  
            // millisecond
        }  
      
        if (/(y+)/.test(format)) {  
            format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));  
        }  
        for (var k in o) {  
            if (new RegExp("(" + k + ")").test(format)) {  
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));  
            }  
        }  
        return format;  
    }  
});
function selectValue(value){
	$('input[value=\"'+value+'\"]').prop("checked",true);
}
function unSelectValue(value){
	$('input[value=\"'+value+'\"]').prop("checked",false);
}
function saveAllInfo(){
	$('.submitInfo').trigger('click');
}
